Repository navigation
Conversation
|
I had a quick look at some of the failed jobs and they seem not related to my changes is this correct? Or is it expected from me to fixe something to get this change merged? |
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
Requesting changes: the PR stops the syntax error but also stops cppcheck from checking ACTION bodies.
- Bodies are no longer analysed (new false negatives).
ACTIONandACTION_Pnow expand to nothing, so the body is left as a bare{ ... }block at namespace scope. Cppcheck doesn't analyse code there. At top level the base config checks these bodies and finds bugs in them; with this PR it reports nothing. The macros should expand to a function header instead, asTESTandMATCHERalready do in this file. I tried that and both the syntax error and the missing warnings went away. ACTION_Pkis not a real gmock macro. gmock usesACTION_P2…ACTION_P10, which this PR doesn't define.ACTION_P2(Foo, p1, p2){}inside a namespace still givessyntaxError. Thekin the PR description is a placeholder, not a macro name.- No tests.
test/cfg/googletest.cppgets no cases for the new defines.
Testing
Built cppcheck from pr/ with make -j8 cppcheck. I didn't build base/: to get the old behaviour I ran the PR's binary with --library=../base/cfg/googletest.cfg. The PR only changes the cfg, so that gives the same results as a base build.
The motivating cases are fixed. namespace{int x;ACTION_P(B, p){}} and namespace{int x;ACTION(B){}} give syntaxError with the base cfg and no error with the PR.
Real ACTION_P2/ACTION_P3 still fail
// c.cpp
namespace{int x;ACTION_P2(Foo, p1, p2){}}$ cppcheck -q --library=googletest c.cpp
c.cpp:1:17: error: syntax error [syntaxError]
Regression: bugs inside ACTION bodies are no longer found
// e.cpp
ACTION(Foo) { int *p = 0; return *p; }
ACTION_P(Bar, n) { char buf[10]; buf[10] = n; return 0; }
void f() { int *p = 0; *p = 1; }With the base cfg (--library=base/cfg/googletest.cfg):
e.cpp:2:37: error: Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]
e.cpp:1:35: error: Null pointer dereference: p [nullPointer]
e.cpp:3:25: error: Null pointer dereference: p [nullPointer]
With the PR (--library=googletest), only the warning in f() is left:
e.cpp:3:25: error: Null pointer dereference: p [nullPointer]
--debug shows why: ACTION(Foo) { ... } turns into a bare block at file scope, 1: { int * p@var1 ; p@var1 = 0 ; return * p@var1 ; }, which is never analysed.
The suggested fix works. I tried these defines in a modified copy of the cfg:
ACTION(name)→auto name##Action(int arg0, int arg1)ACTION_P(name,p0)→template<class p0##_type> auto name##ActionP(p0##_type p0, int arg0)
With them, a.cpp and b.cpp have no syntax error and e.cpp reports all three errors again.
Automated review of ac6bae4 by Claude. The pull request was built and tested locally.
c21b1b6 to
e3cb45e
Compare
|
Updated missing things and added some tests cases. |
|
Thanks for running the CI 👍 i will take an other look into it tomorrow seems the new test doesn't do what i expected in ci |
e3cb45e to
87df375
Compare
|
Tests pass now locally: |
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
The fixes asked for in the earlier review (C2/C3/C4) are in: the ACTION macros now expand to a function header, ACTION_P2…ACTION_P10 exist, and there are tests.
New problem: the implicit action arguments are declared as int (int arg0, int arg1). In real gmock actions these arguments are often pointers or strings, so the PR causes false positives that did not exist before:
AssignmentIntegerToAddressforchar *s = arg1;invalidPrintfArgType_sforprintf("%s", arg0)
It can also send ValueFlow down the wrong path, because arg0 is assumed to be an integer. Making the argument types template parameters fixes this, for example template<class arg0_type, class arg1_type> auto name(const arg0_type& arg0, const arg1_type& arg1). That also matches gmock, which passes them as const argK_type&. I tested this: the false positives go away, and the real bugs in ACTION bodies are still found.
A smaller point: ACTION declares arg0 and arg1, but ACTION_P* declares only arg0, which is inconsistent.
Earlier comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | ACTION bodies no longer analysed (expand to nothing) | AI review | general | ✅ Fixed |
| 2 | ACTION_Pk is not a real macro; ACTION_P2..P10 missing | AI review | general | ✅ Fixed |
| 3 | No tests in test/cfg/googletest.cpp | AI review | general | ✅ Fixed |
| 4 | Expand ACTION to a function header so the body is analysed | AI review | cfg/googletest.cfg:62 |
✅ Fixed |
| 5 | Add ACTION_P2..ACTION_P10 and tests | AI review | cfg/googletest.cfg:64 |
✅ Fixed |
Testing
I built cppcheck from pr/ and found no build problems. To get the base behaviour I ran the PR binary with --library=../base/cfg/googletest.cfg.
- Motivating cases:
ACTION,ACTION_PandACTION_P2at top level and inside namespaces no longer givesyntaxError. Bugs in ACTION bodies are found (nullPointer,uninitvar). - Regression check:
ACTION_TEMPLATEstill givessyntaxError, but it did before the PR as well, so this is not a regression. - New false positives, caused by
arg0/arg1being declared asint:
// c.cpp
#include <cstring>
#include <cstdio>
ACTION(B4) { char *s = arg1; s[0] = 'a'; }
ACTION_P(B5, v) { const char *s = arg0; return strlen(s) + v; }
ACTION(B6) { printf("%s", arg0); }$ ./cppcheck -q --enable=all --inconclusive --library=googletest c.cpp
c.cpp:3:22: portability: Assigning an integer to a pointer is not portable. [AssignmentIntegerToAddress]
c.cpp:4:33: portability: Assigning an integer to a pointer is not portable. [AssignmentIntegerToAddress]
c.cpp:5:14: warning: %s in format string (no. 1) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]
The line numbers above are for this 5-line file. In my original test file they were 6, 7 and 8 because of two more ACTION lines.
- Suggested fix: I edited a copy of the cfg so that
ACTIONandACTION_Puse template types (template<class arg0_type, class arg1_type> auto name(const arg0_type& arg0, const arg1_type& arg1), and the same idea forACTION_P). With it, all three warnings above go away. My other scratch files still reportnullPointer,uninitvarandunassignedVariablein ACTION bodies. - Not run: I did not run the full
test/cfgruntests script. The author reports that it passes locally.
Automated review of 87df375 by Claude. The pull request was built and tested locally.
87df375 to
2040587
Compare
|
Made all ACTION* macros a template |
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. One point from C9 is only partly fixed. ACTION and ACTION_P now take their implicit arguments as const argN_type&, but ACTION_P2…ACTION_P10 still declare int arg0. So the AssignmentIntegerToAddress false positive from C9 still appears for those macros, for example ACTION_P2(Baz, a, b) { const char *s = arg0; ... }. They also still declare only arg0, while ACTION declares arg0 and arg1. The motivating cases no longer give syntaxError, and bugs inside ACTION bodies are still found.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | ACTION/ACTION_P expand to nothing, so their bodies are not analysed | AI review | general | ✅ Fixed |
| 2 | ACTION_Pk is not a real macro; ACTION_P2..P10 are missing | AI review | general | ✅ Fixed |
| 3 | No tests in test/cfg/googletest.cpp | AI review | general | ✅ Fixed |
| 4 | Expand ACTION to a function header so the body is analysed | AI review | cfg/googletest.cfg:62 |
✅ Fixed |
| 5 | Add ACTION_P2..ACTION_P10 and tests | AI review | cfg/googletest.cfg:64 |
✅ Fixed |
| 6 | Implicit args declared as int cause false positives (also ACTION_P* declare only arg0) | AI review | cfg/googletest.cfg:62 |
@fliiiix, please fix, resolve or reply to the open and new comments: #6.
Testing
- Build: built
cppcheckfrom pr/ withmake -j8 cppcheck. It built without problems. I did not buildtestrunnerbecause the PR only changes the cfg and the cfg test. - Base comparison: to get the base results I ran the PR binary with
--library=../base/cfg/googletest.cfg. - cfg test: I ran
test/cfg/googletest.cppby hand with--check-library --inline-suppr --debug-warnings. The new ACTION cases gave no unexpected warnings. The only extra output wasunmatchedSuppressionforvalueFlowBailoutIncompleteVarat lines 24, 106 and 130, and that is likely because my options differ from those inruntests.sh. I did not runruntests.shitself. ACTION_P2still has the C9 false positive:
// a.cpp
#include <cstring>
ACTION_P2(Baz, a, b) { const char *s = arg0; return strlen(s) + a + b; }$ ./cppcheck -q --enable=all --library=pr/cfg/googletest.cfg a.cpp
a.cpp:5:38: portability: Assigning an integer to a pointer is not portable. [AssignmentIntegerToAddress]
The base cfg does not give this warning. The line number is from my full scratch file. ACTION and ACTION_P with string or pointer arguments give no false positives now.
- Unused actions: an
ACTIONthat is never referenced now givesunusedFunctionwith its own name. Before, it gaveunusedFunctionfor the nameACTION, so I don't count this as a regression. Actions that are referenced, such asWillOnce(Foo()), are not reported.
Automated review of 2040587 by Claude. The pull request was built and tested locally.
They seem to fail when they are in a namespace
with a statement before the macro.
Motivating examples:
```
namespace{int x;ACTION_P(B, p){}}
namespace{int x;ACTION(B){}}
namespace{int x;ACTION_P3(B, p0, p1, p3){}}
// Regression
ACTION(Foo) { int *p = 0; return *p; }
```
2040587 to
795c068
Compare
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. The point that C9/C11 left open is fixed. Every ACTION_P* macro, ACTION_P2 to ACTION_P10, now takes its implicit arguments as const arg0_type& arg0, const arg1_type& arg1. So ACTION_P2(Baz, a, b) { const char *s = arg0; ... } no longer gives AssignmentIntegerToAddress, and ACTION and ACTION_P* declare the same arguments. The motivating namespace cases no longer give syntaxError. Bugs inside ACTION bodies are still found, and test/cfg/googletest.cpp passes with the options from runtests.sh.
Comments
9 comments, 0 open, 0 new
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | ACTION/ACTION_P expand to nothing, so bodies are not analysed | AI review | general | ✅ Fixed |
| 2 | ACTION_Pk is not a real macro; ACTION_P2..P10 missing | AI review | general | ✅ Fixed |
| 3 | No tests in test/cfg/googletest.cpp | AI review | general | ✅ Fixed |
| 4 | Expand ACTION to a function header so the body is analysed | AI review | cfg/googletest.cfg:62 |
✅ Fixed |
| 5 | Add ACTION_P2..ACTION_P10 and tests | AI review | cfg/googletest.cfg:64 |
✅ Fixed |
| 6 | Implicit args declared as int cause false positives | AI review | general | ✅ Fixed |
| 7 | ACTION declares arg0 and arg1, ACTION_P* only arg0 | AI review | general | ✅ Fixed |
| 8 | Implicit args declared as int cause false positives; ACTION_P* declare only arg0 | AI review | cfg/googletest.cfg:62 |
✅ Fixed |
| 9 | ACTION_P2..P10 still declare int arg0 (AssignmentIntegerToAddress FP) | AI review | general | ✅ Fixed |
Testing
-
Build:
make -j8 cppcheckin pr/ succeeded. I didn't buildtestrunnerbecause the PR only changes the cfg and its cfg test. -
cfg test: in
test/cfgI ran../../cppcheck --check-library --platform=unix64 --enable=style,information --inconclusive --inline-suppr --error-exitcode=1 --debug-warnings --check-level=exhaustive --suppress=checkersReport --library=googletest googletest.cpp. The only output was anunmatchedSuppressionformissingIncludeSystem, which came from an extra option I added. All the new inline suppressions (autoNoType,nullPointer) were matched. I didn't runruntests.shitself. -
Scratch tests: I ran
./cppcheck -q --enable=all --inconclusive --library=googleteston two scratch files, and compared with the base cfg (--library=../base/cfg/googletest.cfg) where needed. I covered:ACTION_P2withconst char *s = arg0,printf("%s", arg0), and use ofarg2,arg9,argsandreturn_type.ACTION_P10with an out-of-bounds write.ACTION_P5inside an anonymous namespace after a declaration.- Pointer-style bodies (
*arg0 = v,arg0->push_back(s),arg0 == nullptr ? 0 : *arg0). - An uninitialized variable in an ACTION body.
Results:
- No
AssignmentIntegerToAddressorinvalidPrintfArgType_sfalse positives. nullPointer,arrayIndexOutOfBoundsanduninitvarare found in ACTION bodies.- The base cfg gives
syntaxErrorfor theACTION_P5-in-namespace case. The PR gives no error for it. - Actions that are never referenced give
unusedFunctionunder their own name. C11 already noted this.
Automated review of 795c068 by Claude. The pull request was built and tested locally.
They seem to fail when they are in a namespace
with a statement before the macro.
Motivating examples: